package com.mindbook.vip.gawxchatinfo.controller.nostrum;

import com.mindbook.vip.gawxchatinfo.entity.nostrum.PhcClinicalExaminationGuidanceResultInspectionItems;
import com.mindbook.vip.gawxchatinfo.exception.crud.CurdException;
import com.mindbook.vip.gawxchatinfo.service.nostrum.PhcClinicalExaminationGuidanceResultInspectionItemsService;
import com.mindbook.vip.gawxchatinfo.utils.crud.CrudUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @NAME: wxb
 * @DATE: 2022/8/3
 * @DESCRIPTION:
 **/
@Api("原发性肝癌检查指导项-分组情况")
@RestController
@RequestMapping("phcClinicalExaminationGuidanceResultInspectionItems")
public class PhcClinicalExaminationGuidanceResultInspectionItemsController {

    @Autowired
    private PhcClinicalExaminationGuidanceResultInspectionItemsService service;

    @PostMapping("/")
    @ApiOperation("新增")
    private Result add(PhcClinicalExaminationGuidanceResultInspectionItems p) {
        Integer add = service.add(p);

        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_ADD_SUCCESS.getMsg());
    }

    @PutMapping("/")
    @ApiOperation("修改")
    private Result put(PhcClinicalExaminationGuidanceResultInspectionItems p) {
        Integer put = service.put(p);

        CrudUtils.validateUpdateResult(put);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_UPDATE_SUCCESS.getMsg());
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    private Result del(@PathVariable Integer id) {
        Integer integer = service.removeByPrimaryKey(id);

        CrudUtils.validateDeleteResult(integer);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_DELETE_SUCCESS.getMsg());
    }

    @GetMapping("/list")
    @ApiOperation("列表集合")
    private Result findAll() {
        List<PhcClinicalExaminationGuidanceResultInspectionItems> all = service.findAll();

        return ResultUtils.genSuccessResult(all);
    }


    @GetMapping("/groupName/{groupName}")
    @ApiOperation("根据分组名获取选项")
    private Result findByGroupName(@PathVariable String groupName) {

        PhcClinicalExaminationGuidanceResultInspectionItems buyGroupName = service.findBuyGroupName(groupName);

        if (buyGroupName == null) {
            throw new CurdException(ResultEnum.DATA_SELECT_EMPTY);
        }

        return ResultUtils.genSuccessResult(buyGroupName);
    }


}
